package com.avecsys.quotemanager.utils;

import org.icefaces.ace.json.JSONException;
import org.icefaces.ace.json.JSONObject;

/**
 * @author Sam Sundar K
 * 
 */
public class CommonUtils {

	/**
	 * Helper Method to convert a JSON object to Hex format
	 * 
	 * @param jsonObject
	 * @return String in HEX format
	 */
	public static String convertJSONtoHex(JSONObject jsonObject) {
		String jsonString = jsonObject.toString();
		return ByteArrayUtils.byteArrayToHexString(jsonString.getBytes());
	}

	/**
	 * Helper Method to convert a Hex Data to JSON format
	 * 
	 * @param hexData
	 * @return String in HEX format
	 */
	public static JSONObject convertHextoJSON(String hexData)
			throws JSONException {
		byte[] byteFormatData = ByteArrayUtils.hexStringToByteArray(hexData);
		if (byteFormatData != null) {
			String jsonString = new String(byteFormatData);
			return new JSONObject(jsonString);
		}
		return null;
	}
}
